PIC24F
PMP Peripheral Module Library Help


Table Of Contents

1     Library Features. 4

2     Using Library Functions in Your Code. 4

3     Functions. 4

3.1     PMPClose. 4

3.2     PMPIsBufferNEmpty. 4

3.3     PMPIsBufferNFull 4

3.4     PMPOpen. 5

3.5     PMPMasterRead. 5

3.6     PMPMasterWrite. 5

3.7     PMPSetAddress. 5

3.8     PMPSlaveReadBuffers. 6

3.9     PMPSlaveReadBufferN.. 6

3.10       PMPSlaveWriteBuffers. 6

3.11       PMPSlaveWriteBufferN.. 6

4     Macros. 7

4.1     mPMPIsBufferFull() 7

4.2     mPMPIsBufferOverflow() 7

4.3     mPMPClearBufferOverflow() 7

4.4     mPMPClearBufferUnderflow() 7

4.5     mPMPIsBufferEmpty() 7

4.6     mPMPIsBufferUnderFlow() 8

4.7     mPMPSetAddrIncMode(mode) 8

4.8     mPMPSetADRMux(mode) 8

4.9     mPMPSetByteEnablePolarity(polarity) 8

4.10       mPMPSetByteEnable(mode) 8

4.11       mPMPSetChipSelectMode(mode) 8

4.12       mPMPSetChipSelect1Enable(mode) 9

4.13       mPMPSetChipSelect1Polarity(polarity) 9

4.14       mPMPSetChipSelect2Polarity(polarity) 9

4.15       mPMPSetDataMode(mode) 9

4.16       mPMPSetInterruptEnable(mode) 9

4.17       mPMPSetInterruptPriority(priority) 9

4.18       mPMPSetFreeze(mode) 10

4.19       mPMPSetIdle(mode) 10

4.20       mPMPSetInterruptMode(mode) 10

4.21       mPMPSetAddrLatchPolarity(polarity) 10

4.22       mPMPSetPortEnable(mode) 10

4.23       mPMPSetPortMode(mode) 10

4.24       mPMPSetPortPins(value) 10

4.25       mPMPSetReadStrobeEnable(mode) 11

4.26       mPMPSetReadStrobePolarity(polarity) 11

4.27       mPMPSetWaitBegin(wait) 11

4.28       mPMPSetWaitMiddle(wait) 11

4.29       mPMPSetWaitEnd(wait) 11

4.30       mPMPSetWriteStrobeEnable(mode) 11

4.31       mPMPSetWriteStrobePolarity(polarity) 12

4.32       mPMPSetChipSelect2Enable(mode) 12

 


1          Library Features

 

This peripheral library module:

 

·         Is a parallel 8-bit I/O module. PMP stands for Parallel Master Port module.

·         Is specifically designed to communicate with a wide variety of parallel devices, such as communications peripherals, LCDs, external memory devices and microcontrollers.

·         Is highly configurable, since the interface to parallel peripherals varies significantly.

 

2          Using Library Functions in Your Code

 

Library routine parameters can be constructed using either AND based mask or AND_OR based mask setting. For more information on these masks, see 16-bit Peripheral Libraries.

 

Example of Use ( AND_OR mask )

 

Function Call:

 

PMPOpen((BIT_PMP_ON | BIT_FRZ_OFF | BIT_SIDL_OFF | BIT_ADDR_MUX_16_8 |

         BIT_BE_ON | BIT_RD_WR_ON | BIT_USE_CS2_CS1 | BIT_LATCH_LO |

         BIT_CS2_HI | BIT_BE_HI | BIT_RD_HI),

        (BIT_IRQ_BUF | BIT_INC_ADDR_AUTO |

         BIT_DATA_16 | BIT_MODE_MASTER_1 | BIT_WAITB_4_TCY |

         BIT_WAITM_15_TCY | BIT_WAITE_4_TCY),

        (BIT_P_ALL) , (BIT_A0) ,

        (BIT_INT_PRI_3 | BIT_INT_OFF));

 

3          Functions

3.1         PMPClose

 

Function Prototype

void PMPClose(void);

Include

pmp.h

Description

Disables PMP module and disables interrupt.

Arguments

None

Return Value

None

Remarks:

PMCON.PMPEN, IEC2.PMPIE, IFS2.PMPIF are cleared.

Source File:

PMPClose.c

3.2         PMPIsBufferNEmpty

 

Function Prototype

BOOL PMPIsBufferNEmpty(BUFFER buf);

Include

pmp.h

Description

Returns state of PMSTAT.OBxE (output buffer(s) empty bit)

Arguments

buf - (0..3) enum BUFFER is defined in pmp.h.

Return Value

TRUE/FALSE

Remarks:

Use in SLAVE BUFFERED mode, MODE[1:0] = 00 or SLAVE ENHANCED mode, MODE[1:0] = 00  and INCM[1:0]=11.

Source File:

PMPIsBufferNEmpty.c

3.3         PMPIsBufferNFull

 

Function Prototype

BOOL PMPIsBufferNFull(BUFFER buf);

Include

pmp.h

Description

Returns state of PMSTAT.IBxF (input buffer(s) full bit).

Arguments

buf - (0..3) enum BUFFER is defined in pmp.h.

Return Value

TRUE/FALSE

Remarks:

Use in SLAVE BUFFERED mode, MODE[1:0] = 00 or SLAVE ENHANCED mode, MODE[1:0] = 00  and INCM[1:0]=11

Source File:

PMPIsBufferNFull.c

3.4         PMPOpen

 

Function Prototype

void PMPOpen (UINT control, UINT mode, UINT port,

   UINT addrs, BYTE interrupt);

Include

pmp.h

Description

Configures the PMP module as per the input data. Provides method for setting PMP registers using bit masks provided in this header file.

Arguments

control - Control register settings

mode - Parallel port mode register setting

port - Parallel port enable register setting

addrs - Parallel port address register content

interrupt - intereupt setting for PMP

     bit [0:2] - priority setting

     bit [3] - Interrupt Enable/Disable

     bit [4:7] - unsused

Return Value

None

Remarks:

None

Source File:

PMPOpen.c

3.5         PMPMasterRead

 

Function Prototype

WORD PMPMasterRead (void);

Include

pmp.h

Description

Reads an external device.

Arguments

None

Return Value

Returns value read from external device.

Remarks:

Use in MASTER mode 1 or 2, MODE[1:0] = 10, 11.

Source File:

PMPMasterRead.c

 

3.6         PMPMasterWrite

 

Function Prototype

void PMPMasterWrite(WORD value);

Include

pmp.h

Description

If 8-bit data mode is selected, the data appears on 8 data lines. If 16-bit data mode is selected, the lower 8 bits of data are written first, followed by the upper 8 bits of data.

Arguments

value - data to write to external device

Return Value

None

Remarks:

Use in MASTER mode 1 or 2, MODE[1:0] = 10, 11.

Source File:

PMPMasterWrite.c

 

3.7         PMPSetAddress

 

Function Prototype

void PMPSetAddress(WORD addrs);

Include

pmp.h

Description

Sets the address that will appear on the PMP bus addrs lines.

Arguments

addrs - address that needs to appear on the bus

Return Value

None

Remarks:

Use in MASTER mode 1 or 2, MODE[1:0] = 10, 11.

Source File:

PMPSetAddress.c

3.8         PMPSlaveReadBuffers

 

Function Prototype

void PMPSlaveReadBuffers(BYTE* ref);

Include

pmp.h

Description

Copies 4 bytes from DATAIN buffers to a starting location pointed to by the input parameter.

Arguments

ref - BYTE pointer to application buffer

Return Value

The contents of the (4) 8-bit slave buffer registers.

Remarks:

Reading any of these buffers clears the IBF status bit as well as the individual IBnF status bits. Use in MASTER mode 1 or 2, MODE[1:0] = 10, 11.

Source File:

PMPSlaveReadBuffers.c

3.9         PMPSlaveReadBufferN

 

Function Prototype

BYTE PMPSlaveReadBufferN(BUFFER buf)

Include

pmp.h

Description

Reads the value in PMDATA register written by a master device.

Arguments

buf - (0..3) enum BUFFER is defined in pmp.h.

Return Value

The value in selected buffer register.

Remarks:

Reading PMDATA buffer clears status bit. Use in SLAVE BUFFERED mode, MODE[1:0] = 00 and INCM[1:0]=11 or SLAVE ENHANCED mode, MODE[1:0] = 01.

Source File:

PMPSlaveReadBufferN.c

3.10     PMPSlaveWriteBuffers

 

Function Prototype

BOOL PMPSlaveWriteBuffers(BYTE* ref);

Include

pmp.h

Description

Copies 4 bytes, addressed by the pointer/ref argument, into the corresponding output registers. Byte[0] -> OUT1[7:0], byte[1] -> OUT1[15:8], etc. If the entire buffer is empty, (IBF = 0) function returns TRUE; else the bytes are not copied and returns FALSE.

Arguments

ref - BYTE pointer to application buffer.

Return Value

Returns TRUE if successful, else FALSE.

Remarks:

Use in SLAVE BUFFERED mode, MODE[1:0] = 00 and INCM[1:0]=11 or SLAVE ENHANCED mode, MODE[1:0] = 01.

Source File:

PMPSlaveWriteBuffers.c

3.11     PMPSlaveWriteBufferN

 

Function Prototype

BOOL PMPSlaveWriteBufferN(BUFFER buf, BYTE);

Include

pmp.h

Description

Writes the desired value into the selected output buffer.

Arguments

buf - (0..3) enum BUFFER is defined in pmp.h.

Return Value

Returns TRUE if successful, else FALSE.

Remarks:

Use in SLAVE BUFFERED mode, MODE[1:0] = 00 and INCM[1:0]=11 or SLAVE ENHANCED mode, MODE[1:0] = 01.

Source File:

PMPSlaveWriteBufferN.c

 

4          Macros

4.1         mPMPIsBufferFull()

 

Macro

mPMPIsBufferFull()

Include

PwrMgnt.h

Description

Returns state of PMSTAT.IBF (input buffer full bit)

TRUE = All writable input buffer registers are full

FALSE = Some or all of the writable input buffer registers are empty

Arguments

None

Remarks

Use in any SLAVE mode

4.2         mPMPIsBufferOverflow()

 

Macro

mPMPIsBufferOverflow()

Include

PwrMgnt.h

Description

Returns state of PMSTAT.IBOV (input buffer overflow bit)

TRUE = A write attempt to a full input byte register occurred (must be cleared in software)

FALSE = No overflow occurred

Arguments

None

Remarks

Use in any SLAVE mode

4.3         mPMPClearBufferOverflow()

 

Macro

mPMPClearBufferOverflow()

Include

PwrMgnt.h

Description

Clears PMSTAT.IBOV (input buffer overflow bit)

Arguments

None

Remarks

Use in any SLAVE mode

4.4         mPMPClearBufferUnderflow()

 

Macro

mPMPClearBufferUnderflow()

Include

PwrMgnt.h

Description

Clears PMSTAT.OBUF (output buffer underflow bit)

Arguments

None

Remarks

Use in any SLAVE mode

4.5         mPMPIsBufferEmpty()

 

Macro

mPMPIsBufferEmpty()

Include

PwrMgnt.h

Description

Returns state of PMSTAT.OBE (output buffer empty bit)

TRUE = All readable output buffer registers are empty

FALSE = Some or all of the readable output buffer registers are full

Arguments

None

Remarks

Use in any SLAVE mode

4.6         mPMPIsBufferUnderFlow()

 

Macro

mPMPIsBufferUnderFlow()

Include

PwrMgnt.h

Description

Returns state of PMSTAT.OBUF (output buffer underflow bit)

TRUE = A read occurred from an empty output byte register (must be cleared in software)

FALSE = No underflow occurred

Arguments

None

Remarks

Use in any SLAVE mode

4.7         mPMPSetAddrIncMode(mode)

 

Macro

mPMPSetAddrIncMode(mode)

Include

PwrMgnt.h

Description

Sets PMP address inc/dec mode

Arguments

mode - 0= no inc/dec, 1= inc, 2= dec, 3= PSP buffered.

Remarks

None

4.8         mPMPSetADRMux(mode)

 

Macro

mPMPSetADRMux(mux)

Include

PwrMgnt.h

Description

Selects PMP addrs/data multiplexing mode

Arguments

mux - 0= no mux, 1= 8addr/8data muxed, 2= 16addr/8data muxed.

Remarks

None

4.9         mPMPSetByteEnablePolarity(polarity)

 

Macro

mPMPSetByteEnablePolarity(polarity)

Include

PwrMgnt.h

Description

Sets PMP byte enable pin polarity

Arguments

polarity - 0= active lo, 1= active hi.

Remarks

None

4.10     mPMPSetByteEnable(mode)

 

Macro

mPMPSetByteEnable(mode)

Include

PwrMgnt.h

Description

Sets PMP byte enable bit

Arguments

mode - 0=DISABLED, 1=ENABLED.

Remarks

None

4.11     mPMPSetChipSelectMode(mode)

 

Macro

mPMPSetChipSelectMode(mode)

Include

PwrMgnt.h

Description

Sets PMP byte enable bit

Arguments

mode -

   0= CS2 as A15,CS1 as A14;

   1= CS2 as CS2, CS1 as A14;

   2= CS2 as CS2, CS1 as CS1;

   3= reserved.

Remarks

None

4.12     mPMPSetChipSelect1Enable(mode)

 

Macro

mPMPSetChipSelect1Enable(mode)

Include

PwrMgnt.h

Description

Sets PMP chip select 1 pin polarities.

Arguments

mode - 0=DISABLED, 1=ENABLED.

Remarks

None

4.13     mPMPSetChipSelect1Polarity(polarity)

 

Macro

mPMPSetChipSelect1Polarity(polarity)

Include

PwrMgnt.h

Description

Sets PMP chip select pin polarities.

Arguments

polarity - 0= active lo, 1= active hi.

Remarks

None

4.14     mPMPSetChipSelect2Polarity(polarity)

 

Macro

mPMPSetChipSelect2Polarity(polarity)

Include

PwrMgnt.h

Description

Sets PMP chip select pin polarities.

Arguments

polarity - 0= active lo, 1= active hi.

Remarks

None

4.15     mPMPSetDataMode(mode)

 

Macro

mPMPSetDataMode(mode)

Include

PwrMgnt.h

Description

Sets PMP data width to 8 or 16 bit.

Arguments

mode - 0=8-bit, 1=16-bit.

Remarks

None

4.16     mPMPSetInterruptEnable(mode)

 

Macro

mPMPSetInterruptEnable(mode)

Include

PwrMgnt.h

Description

Sets/clears PMP interrupt enable bit.

Arguments

mode - 0=DISABLED, 1=ENABLED.

Remarks

None

4.17     mPMPSetInterruptPriority(priority)

 

Macro

mPMPSetInterruptPriority(priority)

Include

PwrMgnt.h

Description

Sets/clears PMP interrupt priority bits.

Arguments

priority - 0 through 7.

Remarks

None

4.18     mPMPSetFreeze(mode)

 

Macro

mPMPSetFreeze(mode)

Include

PwrMgnt.h

Description

Sets/clears PMP debugging freeze bit.

Arguments

mode - 0=DISABLED, 1=ENABLED.

Remarks

None

4.19     mPMPSetIdle(mode)

 

Macro

mPMPSetIdle(mode)

Include

PwrMgnt.h

Description

Sets/clears PMP "STOP IN IDLE" mode bit.

Arguments

mode - 0=ENABLED, 1=DISABLED.

Remarks

None

4.20     mPMPSetInterruptMode(mode)

 

Macro

mPMPSetInterruptMode(mode)

Include

PwrMgnt.h

Description

Selects PMP interrupt mode.

Arguments

mode - 0=no INT, 1=INT on R/W, 2=INT on buffer full, 3= reserved.

Remarks

None

4.21     mPMPSetAddrLatchPolarity(polarity)

 

Macro

mPMPSetAddrLatchPolarity(polarity)

Include

PwrMgnt.h

Description

Sets PMP address latch pin polarity.

Arguments

polarity - 0= active lo, 1= active hi.

Remarks

None

4.22     mPMPSetPortEnable(mode)

 

Macro

mPMPSetPortEnable(mode)

Include

PwrMgnt.h

Description

Sets/clears PMP module enable bit.

Arguments

mode - 0=DISABLED, 1=ENABLED.

Remarks

None

4.23     mPMPSetPortMode(mode)

 

Macro

mPMPSetPortMode(mode)

Include

PwrMgnt.h

Description

Sets PMP mode of operation as a slave or master.

Arguments

mode - 0= PSP legacy, 1= PSP enhanced, 2= Master2, 3= Master1.

Remarks

None

4.24     mPMPSetPortPins(value)

 

Macro

mPMPSetPortPins(value)

Include

PwrMgnt.h

Description

Sets PMP addrs, latch and CS pins as either functional or I/O.

Arguments

value - 0000h-FFFFh.

Remarks

None

4.25     mPMPSetReadStrobeEnable(mode)

 

Macro

mPMPSetReadStrobeEnable(mode)

Include

PwrMgnt.h

Description

Sets/clears Read/Write Strobe Port Enable bit.

Arguments

mode -

   1 = PMRD/PMWR port enabled

   0 = PMRD/PMWR port disabled

Remarks

None

4.26     mPMPSetReadStrobePolarity(polarity)

 

Macro

mPMPSetReadStrobePolarity(polarity)

Include

PwrMgnt.h

Description

Sets PMP read pin polarity.

Arguments

polarity - 0= active lo, 1= active hi.

Remarks

None

4.27     mPMPSetWaitBegin(wait)

 

Macro

mPMPSetWaitBegin(wait)

Include

PwrMgnt.h

Description

Sets PMP beginning phase wait time.

Arguments

wait - (0..3) cycles.

Remarks

None

4.28     mPMPSetWaitMiddle(wait)

 

Macro

mPMPSetWaitMiddle(wait)

Include

PwrMgnt.h

Description

Sets PMP middle phase wait time.

Arguments

wait - (0..15) cycles.

Remarks

None

4.29     mPMPSetWaitEnd(wait)

 

Macro

mPMPSetWaitEnd(wait)

Include

PwrMgnt.h

Description

Sets PMP end phase wait time.

Arguments

wait - (0..3) cycles.

Remarks

None

4.30     mPMPSetWriteStrobeEnable(mode)

 

Macro

mPMPSetWriteStrobeEnable(mode)

Include

PwrMgnt.h

Description

Sets PMP Write Enable Strobe Port Enable bit.

Arguments

mode -

   1 = PMWR/PMENB port enabled

   0 = PMWR/PMENB port disabled

Remarks

None

4.31     mPMPSetWriteStrobePolarity(polarity)

 

Macro

mPMPSetWriteStrobePolarity(polarity)

Include

PwrMgnt.h

Description

Sets PMP write pin polarity.

Arguments

polarity - 0= active lo, 1= active hi.

Remarks

None

4.32     mPMPSetChipSelect2Enable(mode)

 

Macro

mPMPSetChipSelect2Enable(mode)

Include

PwrMgnt.h

Description

Sets PMP chip select 2 pin.

Arguments

mode - 0=DISABLED, 1=ENABLED.

Remarks

None